package com.yifeng.repo.controller.statemachine.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletContextInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * Created by daibing on 2024/9/21.
 */
@Slf4j
public class StatemachineServletRegistrar implements ServletContextInitializer {
    private final String apiPrefix;

    public StatemachineServletRegistrar(String apiPrefix) {
        this.apiPrefix = apiPrefix;
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        StatemachineServlet servlet = new StatemachineServlet(apiPrefix);
        ServletRegistration.Dynamic registration = servletContext.addServlet("StatemachineServlet", servlet);
        registration.addMapping(apiPrefix + "/*");
        registration.setLoadOnStartup(1);
        log.info("yfcloud controller open status api success: statemachine");
    }
}
